﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Collections;

namespace DomusDotNet.Sbm.Client.SL4.Infrastructure
{
    public class StringJoinConverter: IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var nullText =  parameter == null ? "-" : parameter.ToString();
            var list = value as IEnumerable;
            if (list == null) return null;

            var parts = list.Cast<object>()
                .Select(x => x ?? nullText)
                .ToArray();

            return string.Join(culture.TextInfo.ListSeparator, parts);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
